package main

import (
	"fmt"
	"gopkg.in/mgo.v2/bson"
)

type Person struct {
	Name string
	Age  int
}

func main() {
	out, err := bson.Marshal(&Person{
		Name: "tb",
		Age:  0,
	})
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("%q", out)

	//定义返回值类型
	p := Person{}
	err = bson.Unmarshal(out, &p)
	if err != nil {
		panic(err)
	}
	fmt.Println(p)

	Arr := []Person{
		{
			Name: "jerry",
			Age:  0,
		},

		{
			Name: "tom",
			Age:  12,
		},
	}

	outArrByte, err := bson.Marshal(Arr)

	//map[string]interface
	stringMap := bson.M{}
	err = bson.Unmarshal(outArrByte, stringMap)
	fmt.Println(stringMap)
}
